package com.example.twoeightgang;

import android.util.Log;

import java.util.HashMap;
import java.util.Random;

public class StartGame {
//    private String[] num={"1","2","3","4","5","6","7","8","9","10"};
//    private String[] huase={"黑桃","红桃","梅花","方块"};
    String[] puke={"heitao1","hongtao1","meihua1","fangkuai1",
            "heitao2","hongtao2","meihua2","fangkuai2",
            "heitao3","hongtao3","meihua3","fangkuai3",
            "heitao4","hongtao4","meihua4","fangkuai4",
            "heitao5","hongtao5","meihua5","fangkuai5",
            "heitao6","hongtao6","meihua6","fangkuai6",
            "heitao7","hongtao7","meihua7","fangkuai7",
            "heitao8","hongtao8","meihua8","fangkuai8",
            "heitao9","hongtao9","meihua9","fangkuai9",
            "heitao10","hongtao10","meihua10","fangkuai10"};
    int[] pkNum={1,1,1,1,
                2,2,2,2,
                3,3,3,3,
                4,4,4,4,
                5,5,5,5,
                6,6,6,6,
                7,7,7,7,
                8,8,8,8,
                9,9,9,9,
                10,10,10,10};

    HashMap hashMap;
    int[] twoPk;
    private int middlePK;

    StartGame(){
        init();
        Log.d("kaikai","has = " + this.hashMap.get(5));
        Log.d("kaikai","has = " + this.hashMap.get(5));

    }

    public void init(){
        this.hashMap=this.addPk(this.puke);
        this.twoPk=randomCommon(0,39,9);
        for(int i=0;i<this.twoPk.length;i++){
            Log.d("ykk","this.twoPk " + i + " == " + this.twoPk[i]);
        }
    }


    public HashMap addPk(String[] a){
        HashMap allPk=new HashMap();
        for(int i=0;i<a.length;i++){
            allPk.put(i,a[i]);
            //Log.d("ykk","addPK = " + a[i]);
        }
        return allPk;
    }

    public int[] fapai(String[] puken){
        Random random = new Random();
        int[] a=new int[9];
        for(int i = 0;i < a.length;i++) {
            int suiji = random.nextInt(puken.length);
            for (int j = 0; j <= i; j++) {
                if (suiji != a[j]) {
                    a[i] = suiji;
                }
                Log.d("ykk","a" + i + " == " + a[i]);
            }
        }
        return a;
    }

    public static int[] randomCommon(int min, int max, int n){
        if (n > (max - min + 1) || max < min) {
            return null;
        }
        int[] result = new int[n];
        int count = 0;
        while(count < n) {
            int num = (int) (Math.random() * (max - min)) + min;
            boolean flag = true;
            for (int j = 0; j < n; j++) {
                if(num == result[j]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                result[count] = num;
                count++;
            }
        }
        return result;
    }


    public String getDanzhang(int i){
        String ddd="";
        if(this!=null){
            HashMap newH=this.hashMap;
            ddd=newH.get(this.twoPk[i]).toString();
        }
        return ddd;
    }

    public int getDanzhangNum(int i){
        int[] mInt=this.pkNum;
        return mInt[this.twoPk[i]];
    }


}
